package cn.xuqiudong.sso.shiro.d20250228;

import org.apache.shiro.mgt.DefaultSecurityManager;
import org.apache.shiro.realm.SimpleAccountRealm;
import org.apache.shiro.subject.Subject;

/**
 * 描述:
 *
 * @author Vic.xu
 * @since 2025-02-28 14:55
 */
public class ShiroConfig {

    public static void initShiro() {
        // 创建一个简单的 Realm
        SimpleAccountRealm realm = new SimpleAccountRealm();
        realm.addAccount("testUser", "testPassword");

        // 创建安全管理器
        DefaultSecurityManager securityManager = new DefaultSecurityManager(realm);
        org.apache.shiro.SecurityUtils.setSecurityManager(securityManager);

        // 模拟用户登录
        Subject currentUser = org.apache.shiro.SecurityUtils.getSubject();
        currentUser.login(new org.apache.shiro.authc.UsernamePasswordToken("testUser", "testPassword"));
    }
}
